<?

if(!defined(SCOT_COOCCURRENCE)) {
	define('SCOT_COOCCURRENCE', true);

	class Cooccurrence {
		var $tagIDList = null;
		var $cooccurrenceid = 0;
		var $aFreq = 0;
		var $caFreq = 0;
		var $tagList = null;
	
		function Cooccurrence($cooccurrenceid, $taglist) {
			if(SCOT_DEBUG) echo('Call : Cooccurrence->Cooccurrence()<br>');
			
			$this->cooccurrenceid = $cooccurrenceid;
			$this->aFreq = 1;
			$this->caFreq = 1;
			$this->tagIDList = $taglist;
			$this->tagList = array();
		}
		
		function getAFrequency() {
			if(SCOT_DEBUG) echo('Call : Tag->getAFrequency()<br>');
			
			return $this->aFreq;
		}

		function setAFrequency($freq) {
			if(SCOT_DEBUG) echo('Call : Tag->setAFrequency()<br>');
			
			$this->aFreq = $freq;
		}
		
		function getCAFrequency() {
			if(SCOT_DEBUG) echo('Call : Tag->getCAFrequency()<br>');
			
			return $this->caFreq;
		}

		function setCAFrequency($freq) {
			if(SCOT_DEBUG) echo('Call : Tag->setCAFrequency()<br>');
			
			$this->caFreq = $freq;
		}

		function getRFrequency($total) {
			return ($this->aFreq / $total * 100);
		}
		
		function getCRFrequency($total) {
			return ($this->caFreq / $total * 100);
		}

		function addTag($tag) {
			$this->tagList[] = $tag;
		}
		
		function getTagList() {
			return $this->tagList;
		}
		
		function getTagIDSubSet() {
			$tagidsubset = array();
		
			$temp = 1;
			for($i = 0 ; $i < count($this->tagIDList) ; $i++) {
				$temp *= 2;
			}
			
			for($i = 1 ; $i < $temp - 1; $i++) {
				$array = array();
				
				for($j = 0 ; $j < count($this->tagIDList) ; $j++) {
					if((($i >> $j) & 1) == 1) {
						$array[] = $this->tagIDList[$j];
					}
				}
				
				$tagidsubset[] = $array;
			}
			
			return $tagidsubset;
		}
		
		function isSame($taglist) {
			$dif1 = array_diff($taglist, $this->tagIDList);
			$dif2 = array_diff($this->tagIDList, $taglist);
			return ($dif1 == $dif2)?1:0;
		}
		
		function getName() {
			return $this->cooccurrenceid;
		}
		
		function getTagIDListToString() {
			$list = '{';
			for($i = 0 ; $i < count($this->tagIDList) - 1; $i++) {
				$list .= $this->tagIDList[$i].', ';
			}
			$list .= $this->tagIDList[$i].'}';
			return $list;
		}
		
		function getTagIDList() {
			return $this->tagIDList;
		}
	}
}
?>